import { BaseApi } from "@/apis/base.api";
import { useUserStore } from "@/stores/user.store";
import { useSysConfig } from "@/configs/sys.config";

export default function useUser() {

  // 刷新用户信息
  const refresh = async () => {
    const userResponse = await BaseApi.auth.getUserInfo();
    useUserStore().setUserInfo(userResponse.data);
    // 获取当前平台菜单
    const userMenus = useUserStore().userInfo.menuGroupList?.find((menuGroup:any) => menuGroup.code === useSysConfig().project)?.menuList || [];
    useUserStore().setUserMenus(userMenus);
  }

  return { refresh };
}